#!/bin/bash
#用法说明
usage(){
        echo "Usage: $0 -s <file> -i <path> -o <path>"
        echo
        echo "Options:"
        echo "  -h, --help           Show this help message"
        echo "  -s, --species        Enter a file containing name of species"
        echo "  -i, --inputpath      Directory of the raw data"
        echo "  -o, --outpath        The target directory contains data for subsequent analysis"
        echo "The analysis result would be output in the running directory."
        echo
        exit 0
}

while [ $# -gt 0 ]; do
        case "$1" in
                -h|--help)
                        usage
                        ;;
                -s|--species)
                        species="$2"
                        shift 2
                        ;;
                -i|--inputpath)
                        inputpath="$2"
                        shift 2
                        ;;
                -o|--outpath)
                        outpath="$2"
			shift 2
			;;
	esac
done


# 针对物种在分析目录中拷贝需要的文件并开启基因富集区域（GRR）识别分析
# 结果：每个物种需要的四个文件在data目录中以物种名为文件夹名下
# 每一步分析都存储在对应步骤的文件夹下，例如第一步分析结果在01.cluster_result以及01.local_density_json目录下
mkdir -p ${outpath}
(cd ${outpath}; bash one_script_run_all_steps.sh ${species} ${inputpath} ${outpath})

# 这里默认了${outpath}就是当前目录？
# 跑完分析后，将基因信息表、基因组统计信息表、最后生成的json文件都上传到服务器上
rsync -avzpL -e 'ssh -p 2222' ${outpath}/16.species_statistics/genome_statistic_info.csv  ${outpath}/17.gene_info/gene_info.csv admin@49.7.230.87:/var/www/html/SynColV/public/data/system/

cat species | while read a; do
	rsync -avzpL -e 'ssh -p 2222' ${outpath}/18.production/${a} admin@49.7.230.87:/var/www/html/SynColV/public/data/species_summary/
done
